﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _1010PhotoManagement
{
    public partial class AMForm : Form
    {
        

        public string PictName { get; set; }
        public DateTime PictDate { get; set; }
        public string PictIntro { get; set; }
        public string PictPath { get; set; }

        public AMForm()
        {
            InitializeComponent();
            dateTimePicker1.CustomFormat = "yyyy年MM月dd日";
            dateTimePicker1.Format = DateTimePickerFormat.Custom;
            PictPath = "";
            pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
        }
      
        //如果因照片修改而打开本窗体，则在Load事件中通过标题栏的内容判断
        //并将被修改照片的信息显示在窗体中
        private void AMForm_Load(object sender, EventArgs e)
        {
            if (this.Text == "修改照片信息")
            {
                textBox1.Text = PictName;
                textBox2.Text = PictIntro;
                dateTimePicker1.Value = PictDate;
                pictureBox1.Image = new Bitmap(PictPath);
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();
            of.Filter = "Jpeg图片|*.jpg|位图 (*.bmp)|*.bmp|All files (*.*)|*.*";
            if (DialogResult.OK == of.ShowDialog())
            {
                PictPath = of.FileName;//用户在对话框上选中的文件
                if (pictureBox1.Image != null) pictureBox1.Image.Dispose();
                pictureBox1.Image = new Bitmap(of.FileName);
            }
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            if (PictPath.Length == 0)
            {
                MessageBox.Show("请导入照片"); return;
            }
            else if (textBox1.Text.Trim().Length == 0)
            {
                MessageBox.Show("请输入照片名称"); return;
            }
            else
            {
                PictName = textBox1.Text;
                PictDate = dateTimePicker1.Value;
                PictIntro = textBox2.Text;
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }
    }
}
